#include "tools/utils.h"



// 安全随机数生成器
uint32_t get_secure_random() {
    uint32_t random_value;
    
#ifdef _WIN32
    HCRYPTPROV hProv;
    
    if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
        CryptGenRandom(hProv, sizeof(random_value), (BYTE*)&random_value);
        CryptReleaseContext(hProv, 0);
    } else {
        random_value = rand();
    }
#else
    int fd = open("/dev/urandom", O_RDONLY);
    if (fd >= 0) {
        read(fd, &random_value, sizeof(random_value));
        close(fd);
    } else {
        // 初始化随机数种子
        static int initialized = 0;
        if (!initialized) {
            srand((unsigned int)time(NULL) ^ getpid());
            initialized = 1;
        }
        random_value = rand();
    }
#endif
    
    return random_value;
}

